import type { FcPageConfig } from '@/types/fcform'
import { createSearchForm } from './search/index.ts'
import { createColums } from './table/columns.ts'
import { createFormItems } from './edit/formItems.ts'
import { createRules } from './edit/rules.ts'
import { createFormItems as createPassItems } from './pass/formItems.ts'
import { createRules as createPassRule } from './pass/rules.ts'
import { usePageConfig as deptConfig } from '@/views/setting/department/config/index.ts'
const dept = deptConfig()
export function usePageConfig(): FcPageConfig {
  return {
    KEY: 'userId',
    pageProps: {
      createSearchForm,
      tools: {
        add: {
          auth: 'sys_user_add',
        },
        del: {
          auth: 'sys_user_del',
        },
      },
    },
    table: {
      getApi: '/admin/user/page',
      delApi: {
        api: '/admin/user/del',
        method: 'delete',
        isArray: true,
      },
      initForm: {
        deptId: null,
        username: '',
        phone: '',
      },
      createColums,
    },
    edit: {
      default: {
        addApi: '/admin/user',
        editApi: {
          api: '/admin/user',
          method: 'put',
        },
        saveParams: (params) => {
          const reg = /[\t\r\f\n\s]*/g
          params.username = params.username.replace(reg, '')
          return params
        },
        createItems: createFormItems,
        createRule: createRules,
      },
      pass: {
        title: () => '修改密码',
        addApi: {
          api: '/admin/user/password2',
          method: 'put',
          successText: '修改成功',
        },
        saveParams: (params) => {
          return {
            userId: params.userId,
            newpassword1: params.newpassword1,
          }
        },
        createItems: createPassItems,
        createRule: createPassRule,
      },
      dept: dept.edit.default,
    },
  }
}
